{%extends "base.html"%}

{%block content%}
<div class = "navigation" id = "top_navigation">
    <a href = "/home">Home</a>
    {%for p in product.category.get_parents_line%}
    -><a href = "/categories/{{p.as_url}}/">{{p}}</a>
    {%endfor%}
    -><a href = "/categories/{{product.category.as_url}}">{{product.category}}</a>
    &nbsp;&lt;=== You're here!
</div>
<div class = "span-12">
    <div id = "product_detail">
        <span class = "text_info">
            <div class = "name"><strong>{{product.name}}</strong></div>
            <div class = "cost">Cost: {{product.cost}} &euro;</div>
            <div class = "description">Description:<br>{{product.description}}</div>
        </span>
    </div>
    <form action = "/cart/add/" method = "post">
        {%csrf_token%}
        <input style = "width: 50px;" type = "text" name = "count" value = "1">
        <button>Add</button>
        <input type = "hidden" name = "product_id" value = "{{product.pk}}">
    </form>
    {%if user.is_authenticated%}
    <strong><a href = "/ref/userinvite/{{user.username}}/{{product.pk}}/">Reflink</a></strong>
    {%endif%}
</div>
<hr>
    {%block comments%}
        <div class = "comments">
            {%for c in comments%}
            <div class = "comment{%if c.is_shadowed%} shadowed{%endif%}" id = "comment{{c.pk}}">
                
                {%for i in c.iter_depth%}
                <span class = "wrap">
                {%endfor%}
                {%if show_hidden or not c.is_hidden%}
                    <div class = "comment-content{%if c == just_added%} just_added{%endif%}">
                        <span class = "header">
                            by <em><strong>{{c.owner}}</strong></em>
                            at {{c.time}}
                            <a href = "#comment{{c.pk}}">#</a>
                            {%if c.get_parent%}<a href = "#comment{{c.get_parent.pk}}">Up</a>{%endif%}
                            <span class = "mark">
                                <span class = "likes">{{c.get_likes.count}}</span> |
                                <span class = "dislikes">{{c.get_dislikes.count}}</span>
                                {%if c.has_votes%}| <span class = "avg">Avg: {{c.mark}}</span>{%endif%}
                                {%if user.is_authenticated and c.votingobject_ptr not in voted and user.profile != c.owner and not user.profile.is_banned%}
                                <form method = "post" action = "like_{{c.pk}}/">
                                    {%csrf_token%}
                                    <button>Agree</button>
                                </form>
                                <form method = "post" action = "dislike_{{c.pk}}/">
                                    {%csrf_token%}
                                    <button>Disagree</button>
                                </form>
                                {%endif%}
                            </span>
                        </span><br>
                        <div class = "comment-text">{{c.text}}</div>
                    </div>
                    {%if not user.is_authenticated or not user.profile.is_banned%}
                    <a href = "#ans_{{c.pk}}">Answer</a>
                    {%endif%}
                    <div class = "before_form" id = "ans_{{c.pk}}"></div>
                    <div>
                        <form class = "answer_form" action = "add_comment/" method = "post">
                            {%csrf_token%}
                            <input type = "hidden" name = "answer_to" value = "{{c.pk}}">
                            <textarea name = "text"></textarea>
                            <button>Answer</button>
                        </form>
                    </div>
                {%else%}
                    <hr style = "padding:0; margin:0 0 0 0; background-color: red; width: 300px; height: 5px;">
                {%endif%}
                {%for i in c.iter_depth%}
                </span>
                {%endfor%}
            </div>                
            {%endfor%}
        </div>
        <hr>
        <div class = "add_comment">
        {%if user.is_authenticated and user.profile.is_banned%}
        <h1>You are banned until {{user.profile.unban_time}}</h1><hr>
        {%else%}
            <form id = "add_comment_form" action = "add_comment/" method = "post">
                {%csrf_token%}
                <!--<input type = "text" name = "answer_to">-->
                <textarea name = "text"></textarea>
                <button>Add comment</button>
            </form>
        {%endif%}
        </div>
    {%endblock%}
{%endblock%}
